*******************************************************************************;
*******************************************************************************;
*This do file generates Appendix Table A-1: Summary Statistics
*******************************************************************************;
*******************************************************************************;

use $scratch/final_skills_peers.dta, clear

egen idgrade = group(idschool class)

egen school_size = count(idschool) , by(idschool)
egen grade_size = count(idgrade), by(idgrade)


keep if school_size>=200
keep if class >=9 & class<=12
keep if idschool<100 | (idschool>=200 & idschool<300) 

egen gpa = rowmean(cogn2 cogn3 cogn4 cogn5)
egen gpa_t2 = rowmean(cogn2_t2 cogn3_t2 cogn4_t2 cogn5_t2)


*Authoritarian Style;
recode H1WP2 (0=1) (1=0) , gen(authoritarian_parents)
recode H2WP2 (0=1) (1=0) , gen(authoritarian_parents_t2)

egen gpa_peers = rowmean(mean_peer_cogn2 mean_peer_cogn3 mean_peer_cogn4)
egen gpa_peers_t2 = rowmean(mean_peer_cogn2_t2 mean_peer_cogn3_t2 mean_peer_cogn4_t2 mean_peer_cogn5_t2)

local ind = 1
foreach x in H1WP1  H1WP3  H1WP6  {
recode `x' (0=1) (1=0), gen(authoritarian_parents`ind')
local ++ind
}

local ind = 1
foreach x in  H2WP1 H2WP3  H2WP6  {
recode `x' (0=1) (1=0), gen(authoritarian_parents`ind'_t2)
local ++ind
}


**********************************************;
**********************************************;
*Create Samples
**********************************************;



**********************************************;
*Descriptive Stats for Estimating Samples;
**********************************************;

egen temp = group(idschool)
qui sum temp
gen n_schools = r(max)



label variable cogn2 "English Grade"
label variable cogn3 "Math Grade"
label variable cogn4 "History Grade"
label variable cogn5 "Science Grade"

label variable cogn2_t2 "English Grade"
label variable cogn3_t2 "Math Grade"
label variable cogn4_t2 "History Grade"
label variable cogn5_t2 "Science Grade"

label variable cogn1 "PPVT Score"
label variable inv4 "Talked with your mom about a party you attended"
label variable inv6 "Talked with your mom about a personal problem"
label variable inv9 "Worked with your mom on a project for school"

label variable inv4_t2 "Talked with your mom about a party you attended"
label variable inv6_t2 "Talked with your mom about a personal problem"
label variable inv9_t2 "Worked with your mom on a project for school"


label variable authoritarian_parents "Do your parents let you choose your own friends?"
label variable authoritarian_parents_t2 "Do your parents let you choose your own friends?"

label variable authoritarian_parents1 "Do your parents let you choose the time you must be home on weekend nights?"
label variable authoritarian_parents1_t2 "Do your parents let you choose the time you must be home on weekend nights?"

label variable authoritarian_parents2 "Do your parents let you choose what you wear?"
label variable authoritarian_parents2_t2 "Do your parents let you choose what you wear?"

label variable authoritarian_parents3 "Do your parents let you choose what time you go to bed on week nights?"
label variable authoritarian_parents3_t2 "Do your parents let you choose what time you go to bed on week nights?"


label variable real_family_income "Real family income (in 2016 USD)"

label variable gpa "Child's GPA"
label variable gpa_t2 "Child's GPA"

label variable  gpa_peers "Peer GPA"
label variable  gpa_peers_t2 "Peer GPA"

label variable n_schools "N of Schools"





estpost tabstat cogn2 cogn3 cogn4 cogn5 gpa  , statistics(mean sd count) columns(statistics) 
#delimit ;
esttab  , cells("mean(fmt(2)) sd(fmt(2)) count(fmt(%9.0fc))" ) noobs nomtitle nonumber label replace nodepvars collabels(none)
  prehead( " \begin{tabular}{lccc} \hline \hline  & \multicolumn{3}{c}{Wave I: In-School Inteview} \\ ")  posthead(" &  Mean & SD & Obs \\ \cline{2-4} ")
 postfoot("")  
 nomtitles
 ;
#delimit cr

estpost tabstat gpa_peers  , statistics(mean sd count) columns(statistics) 
#delimit ;
esttab , cells("mean(fmt(2)) sd(fmt(2)) count(fmt(%9.0fc))" ) noobs nomtitle nonumber label append nodepvars  collabels(none)
  prehead( "")  posthead("")
 postfoot("")  
 nomtitles
 ;
#delimit cr

estpost tabstat n_schools , statistics(mean) columns(statistics) 
#delimit ;
esttab , cells("mean(fmt(0)) sd(fmt(0)) count(fmt(%9.0fc))" ) noobs nomtitle nonumber label append nodepvars  collabels(none)
  prehead( "")  posthead("")
 postfoot("\hline ")  
 nomtitles
 ;
#delimit cr

estpost tabstat cogn1 inv4  inv6 inv9 authoritarian_parents authoritarian_parents1 authoritarian_parents2 authoritarian_parents3   , statistics(mean sd count) columns(statistics) 
#delimit ;
esttab , cells("mean(fmt(2)) sd(fmt(2)) count(fmt(%9.0fc))") noobs nomtitle nonumber label append nodepvars  collabels(none)
  prehead( "   & \multicolumn{3}{c}{Wave I: In-Home Inteview} \\ ")  posthead(" &  Mean & SD & Obs \\ \cline{2-4} ")
 postfoot("\hline")   
 nomtitles
 ;
#delimit cr


estpost tabstat cogn2_t2 cogn3_t2 cogn4_t2 cogn5_t2 gpa_t2 if gpa_t2!=. , statistics(mean sd count) columns(statistics) 
#delimit ;
esttab , cells("mean(fmt(2)) sd(fmt(2)) count(fmt(%9.0fc))" ) noobs nomtitle nonumber label append nodepvars collabels(none)
  prehead( "   & \multicolumn{3}{c}{Wave II: In-Home Inteview} \\ ")  posthead(" &  Mean & SD & Obs \\ \cline{2-4} ")
  postfoot("")  
 nomtitles
 ;
#delimit cr

estpost tabstat   gpa_peers_t2 inv4_t2  inv6_t2 inv9_t2  authoritarian_parents_t2 authoritarian_parents1_t2 authoritarian_parents2_t2 authoritarian_parents3_t2, statistics(mean sd count) columns(statistics) 
#delimit ;
esttab , cells("mean(fmt(2)) sd(fmt(2)) count(fmt(%9.0fc))" ) noobs nomtitle nonumber label append nodepvars  collabels(none)
  prehead( "")  posthead("")
 postfoot("\hline \hline \end{tabular}")   
 nomtitles
 ;
#delimit cr


******************************************;
******************************************;
*Saturated Schools only;
******************************************;
******************************************;


use $scratch/final_skills_peers.dta, clear

egen idgrade = group(idschool class)

egen school_size = count(idschool) , by(idschool)
egen grade_size = count(idgrade), by(idgrade)

keep if class >=9 & class<=12
keep if sat==1
 
egen gpa = rowmean(cogn2 cogn3 cogn4 cogn5)
egen gpa_t2 = rowmean(cogn2_t2 cogn3_t2 cogn4_t2 cogn5_t2)
egen gpa_peers = rowmean(mean_peer_cogn2 mean_peer_cogn3 mean_peer_cogn4)
egen gpa_peers_t2 = rowmean(mean_peer_cogn2_t2 mean_peer_cogn3_t2 mean_peer_cogn4_t2 mean_peer_cogn5_t2)


*Authoritarian Style;
recode H1WP2 (0=1) (1=0) , gen(authoritarian_parents)
recode H2WP2 (0=1) (1=0) , gen(authoritarian_parents_t2)

local ind = 1
foreach x in H1WP1  H1WP3  H1WP6  {
recode `x' (0=1) (1=0), gen(authoritarian_parents`ind')
local ++ind
}

local ind = 1
foreach x in  H2WP1 H2WP3  H2WP6  {
recode `x' (0=1) (1=0), gen(authoritarian_parents`ind'_t2)
local ++ind
}



****************************
*Create Sample
****************************

**********************************************;
*Descriptive Stats for Estimating Samples;
**********************************************;

egen temp_id_school = group(idschool)
qui sum temp_id_school
gen n_schools = r(max)


label variable cogn1 "PPVT Score"
label variable cogn2 "English Grade"
label variable cogn3 "Math Grade"
label variable cogn4 "History Grade"
label variable cogn5 "Science Grade"

label variable cogn2_t2 "English Grade"
label variable cogn3_t2 "Math Grade"
label variable cogn4_t2 "History Grade"
label variable cogn5_t2 "Science Grade"

label variable inv4 "Talked with your mom about a party you attended"
label variable inv6 "Talked with your mom about a personal problem"
label variable inv9 "Worked with your mom on a project for school"

label variable inv4_t2 "Talked with your mom about a party you attended"
label variable inv6_t2 "Talked with your mom about a personal problem"
label variable inv9_t2 "Worked with your mom on a project for school"

label variable authoritarian_parents "Do your parents let you choose your own friends?"
label variable authoritarian_parents_t2 "Do your parents let you choose your own friends?"

label variable authoritarian_parents1 "Do your parents let you choose the time you must be home on weekend nights?"
label variable authoritarian_parents1_t2 "Do your parents let you choose the time you must be home on weekend nights?"

label variable authoritarian_parents2 "Do your parents let you choose what you wear?"
label variable authoritarian_parents2_t2 "Do your parents let you choose what you wear?"

label variable authoritarian_parents3 "Do your parents let you choose what time you go to bed on week nights?"
label variable authoritarian_parents3_t2 "Do your parents let you choose what time you go to bed on week nights?"

label variable real_family_income "Real family income (in 2016 USD)"

label variable gpa "Child's GPA"
label variable gpa_t2 "Child's GPA"
label variable  gpa_peers "Peer GPA"
label variable  gpa_peers_t2 "Peer GPA"
label variable n_schools "N of Schools"


estpost tabstat cogn2 cogn3 cogn4 cogn5 gpa  , statistics(mean sd count) columns(statistics) 
#delimit ;
esttab  , cells("mean(fmt(2)) sd(fmt(2)) count(fmt(%9.0fc))" ) noobs nomtitle nonumber label replace nodepvars collabels(none)
  prehead( " \begin{tabular}{lccc} \hline \hline  & \multicolumn{3}{c}{Wave I: In-School Inteview} \\ ")  posthead(" &  Mean & SD & Obs \\ \cline{2-4} ")
 postfoot("")  
 nomtitles
 ;
#delimit cr

estpost tabstat gpa_peers  , statistics(mean sd count) columns(statistics) 
#delimit ;
esttab , cells("mean(fmt(2)) sd(fmt(2)) count(fmt(%9.0fc))" ) noobs nomtitle nonumber label append nodepvars  collabels(none)
  prehead( "")  posthead("")
 postfoot("")  
 nomtitles
 ;
#delimit cr

estpost tabstat n_schools , statistics(mean  ) columns(statistics) 
#delimit ;
esttab , cells("mean(fmt(0)) sd(fmt(0)) count(fmt(%9.0fc))" ) noobs nomtitle nonumber label append nodepvars  collabels(none)
  prehead( "")  posthead("")
 postfoot("\hline ")  
 nomtitles
 ;
#delimit cr

estpost tabstat cogn1 inv4  inv6 inv9 authoritarian_parents authoritarian_parents1 authoritarian_parents2 authoritarian_parents3   , statistics(mean sd count) columns(statistics) 
#delimit ;
esttab , cells("mean(fmt(2)) sd(fmt(2)) count(fmt(%9.0fc))"  ) noobs nomtitle nonumber label append nodepvars  collabels(none)
  prehead( "   & \multicolumn{3}{c}{Wave I: In-Home Inteview} \\ ")  posthead(" &  Mean & SD & Obs \\ \cline{2-4} ")
 postfoot("\hline")   
 nomtitles
 ;
#delimit cr


estpost tabstat cogn2_t2 cogn3_t2 cogn4_t2 cogn5_t2 gpa_t2 if gpa_t2!=. , statistics(mean sd count) columns(statistics) 
#delimit ;
esttab , cells("mean(fmt(2)) sd(fmt(2)) count(fmt(%9.0fc))" ) noobs nomtitle nonumber label append nodepvars collabels(none)
  prehead( "   & \multicolumn{3}{c}{Wave II: In-Home Inteview} \\ ")  posthead(" &  Mean & SD & Obs \\ \cline{2-4} ")
 postfoot("")  
 nomtitles
 ;
#delimit cr

estpost tabstat   gpa_peers_t2 inv4_t2  inv6_t2 inv9_t2  authoritarian_parents_t2 authoritarian_parents1_t2 authoritarian_parents2_t2 authoritarian_parents3_t2 , statistics(mean sd count) columns(statistics) 
#delimit ;
esttab , cells("mean(fmt(2)) sd(fmt(2)) count(fmt(%9.0fc))" ) noobs nomtitle nonumber label append nodepvars  collabels(none)
  prehead("")  posthead("")
 postfoot("\hline \hline \end{tabular}")  
 nomtitles
 ;
#delimit cr
